package com.biye.api.tool.security.pojo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class UserDetail implements UserDetails {

    private String id; // 用户id。符合第三范式，消除传递依赖，系统中用户信息统一的id

    private String username;  // 用户名
    private String password;  // 密码
    private Boolean accountNonExpired;     // 账号是否没过期  0为false,1为true
    private Boolean accountNonLock;    // 账户是否没被锁定
    private Boolean credentialsNonExpired;   // 认证是否没过期
    private Boolean enabled;    // 账号是否可用
    private Collection<? extends GrantedAuthority> authorities;   // 用户的权限集合

    public UserDetail(String id, String username, String password, Boolean enabled, Collection<? extends GrantedAuthority> authority){
        this.id = id;
        this.username = username;
        this.password = password;
        this.enabled = enabled;
        this.authorities = authority;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
//        return accountNonExpired;
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
//        return accountNonLock;
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
//        return credentialsNonExpired;
        return false;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    /**
     * Setter & Getter
     **/
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getAccountNonExpired() {
        return accountNonExpired;
    }

    public void setAccountNonExpired(Boolean accountNonExpired) {
        this.accountNonExpired = accountNonExpired;
    }

    public Boolean getAccountNonLock() {
        return accountNonLock;
    }

    public void setAccountNonLock(Boolean accountNonLock) {
        this.accountNonLock = accountNonLock;
    }

    public Boolean getCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    public void setCredentialsNonExpired(Boolean credentialsNonExpired) {
        this.credentialsNonExpired = credentialsNonExpired;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

}
